$("document").ready(function(){
	//历史搜索与搜索框等宽
	$(".history-search").width($(".search-content").width()+24);
	//搜索框搜索的内容在搜索框中表示
	//$("#user_search").val("搜索的内容");
});
function searchUser(text) {
	$("#searchText").val(text);
	$("#form").submit();
}
function addSearchData() {
	var p = 2;
	var  user_search = $("#searchText").val();
	if($("#searchData").val() != null && $("#searchData").val() != ""){
		p = $("#searchData").val();
	}
	var result = '';
	$.ajax({
		type:'get',
		url:'/search/searchByPage.action?user_search='+user_search+'&p='+p,
		dataType:"json",
		beforeSend:function () {
			$("#addMore").empty();
			$("#addMore").html("<img height='30' width='30' src='/image/loading.gif'/>");
			$("#addMore").addClass("disabled");
		},
		success:function(data){
			if (data.status === "Bad_Sql") {
				sweetAlert("WARNING","没有更多数据了","warning");
			}else if (data.status === "Search_Fail"){
				sweetAlert("WARNING","没有更多数据了","warning");
			}else if (data.status === "Success") {
				for (var i in data.finalList) {
					result += '<div class="col-sm-3 store-div">'
						+ '<a href="/search/toDetail.action?user_id='+data.finalList[i].user_id
						+ '&p=1"><img class="store-img" src="/upload/business/'
						+ data.finalList[i].user_img
						+ '"></a>'
						+ '<h3>'
						+ '<a href="">'
						+ data.finalList[i].user_name
						+ '</a>'
						+ '<a href=""><span>'
						+ data.finalList[i].user_evaluate_num
						+ '</span>人评价</a>'
						+ '</h3>'
						+ '<p>'
						+ '<span class="price-avg">人均￥<strong>'
						+ data.finalList[i].user_avarage_price
						+ '</strong></span>'
						+ '</p>'
						+ '</div>';
				}
				$("#searchDataShow").append(result);
				$("#searchData").val(data.page.currentPage + 1);
				if (data.page.totalRows < data.page.endIndex){
					sweetAlert("Success","数据加载完毕","success");
				}
			}else {
				sweetAlert("WARNING","没有更多数据了","warning");
			}
		},
		complete:function (data) {
			$("#addMore").empty();
			$("#addMore").html("加载更多");
			$("#addMore").removeClass("disabled");
		},
		error:function(jqXHR){
			$("#addMore").empty();
			$("#addMore").html("加载更多");
			$("#addMore").removeClass("disabled");
			sweetAlert("ERROR","错误码"+jqXHR.status,"error");
		}
	});
}